import { getRoleListAPI } from '@/api/rolesAPI'

const queryData = {
  pageNum: 1,
  pageSize: 1000,
  name: ''
}
export function isUnique(code, id) {
  return new Promise((resolve, reject) => {
    getRoleListAPI(queryData)
      .then(res => {
        const { data } = res
        const result = data.find(item => {
          if (id === undefined) { return item.code === code } else {
            return item.code === code && item.id !== id
          }
        })
        resolve(result === undefined)
      }).catch(error => {
        reject(error)
      })
  })
}
